﻿using IOP.SgrA.GLSL;
using IOP.SgrA.SilkNet.Vulkan;
using IOP.SgrA.SilkNet.Vulkan.Scripted;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VkSample1213
{
    [ShaderVersion("460")]
    [GLSLExtension("GL_ARB_separate_shader_objects : enable")]
    [GLSLExtension("GL_ARB_shading_language_420pack : enable")]
    public partial class LandVert : GLSLVert
    {
        [UniformBuffer(0, 0, DescriptorSetTarget.RenderObject)]
        public ConstantVals Vals { get; set; }
        [SampledImage(1, 0, DescriptorSetTarget.RenderObject)]
        public sampler2D TexLand {  get; set; }

        [VertInput(0, Silk.NET.Vulkan.Format.R32G32B32Sfloat)]
        public vec3 Pos {  get; set; }
        [VertInput(1, Silk.NET.Vulkan.Format.R32G32Sfloat)]
        public vec2 InTexCoor {  get; set; }
        [VertInput(2, Silk.NET.Vulkan.Format.R32G32Sfloat)]
        public vec2 InHightCoor { get; set; }
        [ShaderOutput(0)]
        public vec2 OutTexCoor { get; set; }
        [ShaderOutput(1)]
        public float LandHeight {  get; set; }
        [ShaderOutput(2)]
        public vec4 PLocation {  get; set; }
        public override void main()
        {
            OutTexCoor = InTexCoor; //将接收的纹理坐标传递到片元着色器
            vec4 g = texture(TexLand, InHightCoor.xy);
            float tempY = (g.x * Vals.landHighest) + Vals.landHighAdjust;
            LandHeight = tempY; //将顶点的Y 坐标传递给片元着色器
            vec4 landPos = new vec4(Pos.x, tempY, Pos.z, 1);
            gl_Position = Vals.mvp * landPos;//计算顶点的最终位置
            PLocation = Vals.mm * landPos;//计算世界坐标系下顶点位置
        }
    }
}
